package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void createBed(BedDto dto) {
        //dto 转 entity
      Bed bed= BeanUtil.toBean(dto,Bed.class);
      bed.setBedStatus(0);
      bed.setCreateTime(LocalDateTime.now());
      bed.setUpdateTime(LocalDateTime.now());
      bed.setCreateBy(1L);
      bed.setUpdateBy(1L);
      bedMapper.insert(bed);
    }

    @Override
    public BedVo readById(Integer id) {
       Bed bed= bedMapper.selectById(id);
        BedVo bedVo = BeanUtil.toBean(bed, BedVo.class);
        return bedVo;
    }

    @Override
    public void updatrBed(BedDto dto) {
        //dto转entity
        Bed bed = BeanUtil.toBean(dto, Bed.class);
        bedMapper.updatrBed(bed);
    }

    @Override
    public void deleteById(Long id) {
        bedMapper.deleteById(id);
    }

}

